/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.db.UserVOIPManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.UserIdNotExist;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.sql.SQLException;
/*    */ import java.util.Map;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.jsoup.Connection;
/*    */ import org.jsoup.Connection.Method;
/*    */ import org.jsoup.Connection.Response;
/*    */ import org.jsoup.Jsoup;
/*    */ 
/*    */ public abstract class AbstractVOIPReport extends AbstractAction
/*    */ {
/* 24 */   private static Logger logger = Logger.getLogger(AbstractVOIPReport.class
/* 25 */     .getName());
/*    */ 
/*    */   public AbstractVOIPReport(AbstractHttpServlet servlet)
/*    */   {
/* 28 */     super(servlet);
/*    */   }
/*    */ 
/*    */   protected String getSessionId()
/*    */     throws UserIdNotExist
/*    */   {
/* 39 */     UserVOIPManager manager = new UserVOIPManager();
/* 40 */     String userId = null;
/* 41 */     String pwd = null;
/*    */     try {
/* 43 */       Map item = manager.getUserAdminVOIPSetting();
/* 44 */       if ((item == null) || (item.size() == 0)) {
/* 45 */         throw new UserIdNotExist();
/*    */       }
/* 47 */       userId = (String)item.get("UserName");
/* 48 */       pwd = (String)item.get("UserPwd");
/*    */     } catch (DBException e) {
/* 50 */       logger.warn("get voip admin user failed", e);
/* 51 */       throw new UserIdNotExist();
/*    */     } catch (SQLException e) {
/* 53 */       logger.warn("get voip admin user failed", e);
/* 54 */       throw new UserIdNotExist();
/*    */     }
/*    */ 
/* 57 */     if ((userId == null) || (userId.trim().length() == 0) || (pwd == null) || 
/* 58 */       (pwd.trim().length() == 0)) {
/* 59 */       logger.warn("userId or pwd is null");
/* 60 */       throw new UserIdNotExist();
/*    */     }
/*    */     try
/*    */     {
/* 64 */       Connection.Response response = 
/* 65 */         Jsoup.connect("http://app.7moor.com/action?callback=jQuery17207710306676232772_" + Util.random(13))
/* 66 */         .userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/* 67 */         .data("action", "login")
/* 68 */         .data("data", 
/* 69 */         "{\"loginName\":\"" + 
/* 70 */         userId + 
/* 71 */         "\",\"password\":\"" + 
/* 72 */         pwd + 
/* 73 */         "\",\"remember\":false,\"extenType\":\"sip\",\"login_busyType\":\"true\"}")
/* 74 */         .timeout(10000).method(Connection.Method.POST).execute();
/*    */ 
/* 76 */       String body = response.body();
/* 77 */       int start = body.indexOf("(");
/* 78 */       int end = body.lastIndexOf(")");
/* 79 */       if (start <= 0) {
/* 80 */         logger.warn("login failed without start symbol");
/* 81 */         return null;
/*    */       }
/*    */ 
/* 84 */       if (end < start) {
/* 85 */         logger.warn("login failed without end symbol");
/* 86 */         return null;
/*    */       }
/*    */ 
/* 89 */       String json = body.substring(start + 1, end);
/*    */ 
/* 91 */       JSONObject jsonObject = JSONObject.fromObject(json);
/*    */ 
/* 93 */       return Util.getJSONStringValue(jsonObject, "sessionId");
/*    */     } catch (IOException e) {
/* 95 */       logger.warn("get voip report sessionId failed", e);
/*    */     }
/*    */ 
/* 98 */     return null;
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AbstractVOIPReport
 * JD-Core Version:    0.6.1
 */